<template>
  <div >
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 19px">
      <el-breadcrumb-item :to="{ path: '/' }">后台管理</el-breadcrumb-item>
      <el-breadcrumb-item>相册列表</el-breadcrumb-item>
    </el-breadcrumb>
  <el-divider></el-divider>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="id" width="100px" align="center"></el-table-column>
      <el-table-column prop="name" label="名称" width="120" align="center"></el-table-column>
      <el-table-column prop="description" label="简介" width="300" header-align="center"></el-table-column>
      <el-table-column prop="sort" label="自定义排序" width="100px"></el-table-column>
      <el-table-column  label="操作" width="150" header-align="center">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle size="mini" @click="handleEdit(scope.row)"></el-button>
            <el-button type="danger" @click="openDeleteConfirm(scope.row)" icon="el-icon-delete" circle size="mini" ></el-button>
        </template>
      </el-table-column>

    </el-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData:[]
    }
  },
  methods: {
    handleEdit(album){
      let message= '您正在尝试编辑【' + album.id + '-' + album.name + '】的相册详情，改你大爷的改';
      this.$alert(message,'提示',{
        confirmButtonText:'确定'
      });
    },
    handleDelete(album){

      let url = 'http://localhost:9090/albums/'+album.id+'/delete';
      console.log('url='+url);
      this.axios.post(url).then((response) => {
        let responseBody=response.data;
        if(responseBody.state != 20000){
          this.$message.error(responseBody.message)
        }
        if(responseBody.state == 40400|| responseBody.state==20000){
          this.loadAlbumList();
        }
      })
      console.log('删除的id...='+album.id)

    },
    openDeleteConfirm(album) {
      this.$confirm('此操作将永久删除【'+album.name+'】相册, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(album)
      }).catch(() => {});
    },

    loadAlbumList(){
      let url = "http://localhost:9090/albums";
      this.axios.get(url).then((responses) => {
        let responsesBody = responses.data;
        this.tableData= responsesBody.data;
      })
    },


  },
  mounted() {
    console.log("mounted");
    this.loadAlbumList();

  }

}
</script>